﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.eLogistics;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Finance
{
    public partial class RevenueMachineAccountInfo : UserControlBase
    {
        public Guid Id
        {
            get { return Parameters.GetGuid("Id"); }

        }

        public bool ViewModel
        {
            get { return Parameters.GetBoolean("ViewModel", false); }
        }

        protected Guid RouteTypeId
        {
            set { ViewState["RouteTypeId"] = value; }
            get
            {
                if (ViewState["RouteTypeId"] != null)
                    return Guid.Parse(ViewState["RouteTypeId"].ToString());
                return Guid.Empty;
            }
        }

        protected string DeliveryProvince
        {
            set { ViewState["DeliveryProvince"] = value; }
            get
            {
                if (ViewState["DeliveryProvince"] != null)
                    return (ViewState["DeliveryProvince"].ToString());
                return string.Empty;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadInitialData();
            }
        }

        private void LoadInitialData()
        {
            var service = ServiceContainer.GetService<IRevenueMachineAccountService>();
            var revenueMachineAccount = service.GetRevenueMachineAccount(Id, false);
            FormPanelStore1.DataSource = revenueMachineAccount;
            FormPanelStore1.DataBind();

            var orderService = ServiceContainer.GetService<IIssuingOrderService>();
            var order = orderService.GetSimpleIssuingOrder(revenueMachineAccount.IssuingOrderId.Value);
            RouteTypeId = order.RouteTypeId;

            if (order.GoodsUnloadingCost.HasValue)
                txtGoodsUnloadingCost.Text = order.GoodsUnloadingCost.Value.ToString("#,###.00");
            this.txtReceivingOrderDate.Text = order.ReceivingOrderDate.ToString("yyyy-MM-dd");
            txtAcutalShippingDate.Text = (order.ActualShippingDate ?? DateTime.Now).ToString("yyyy-MM-dd");

            GridViewOrderDelivery.DataSource =
                orderService.GetIssuingOrderDeliveryByOrderId(revenueMachineAccount.IssuingOrderId.Value);
            GridViewOrderDelivery.DataBind();

            this.lblTransporationPlanCode.Text = order.TransportationPlanCode;

            txtActualEntruckingBoxAmount.Text = (order.ActualEntruckingBoxAmount).ToString("#,###");
            txtUnitCost.Text = (order.UnitCost ?? 0).ToString("#,###.0000");

            if (order.OrderVolumn.HasValue)
                txtOrdeVolumn.Text = order.OrderVolumn.Value.ToString("#,###.000");
            if (order.ActualOrderVolumn.HasValue)
                txtActualOrdeVolumn.Text = order.ActualOrderVolumn.Value.ToString("#,###.000");
            if (order.OrderWeight.HasValue)
                txtOrderWeight.Text = order.OrderWeight.Value.ToString("#,###.000");
            if (order.ActualOrderWeight.HasValue)
                txtActualOrderWeight.Text = order.ActualOrderWeight.Value.ToString("#,###.000");
            if (order.OrderQuantity.HasValue)
                txtOrderQuantity.Text = order.OrderQuantity.Value.ToString("#,###.00");
            if (order.ActualOrderQuantity.HasValue)
                txtActualOrderQuantity.Text = order.ActualOrderQuantity.Value.ToString("#,###.00");

 
        }

     
      

    }
}